package com.tucc.hello.leetcode.no1_400.no1_200.no41_60.no58;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.lengthOfLastWord("Helloworld"));
    }

    public int lengthOfLastWord(String s) {
        if (s != null && s.length() > 0) {
            s = s.trim();
            int st = s.length() - 1;
            int index = st;
            for (; index >= 0; index--) {
                if (s.charAt(index) == ' ') {
                    break;
                }
            }
            return st - index;
        }
        return 0;
    }

}
